# Dibuat untuk mengimport data awal struktur tipitaka
# -*- coding: utf-8 -*-

__author__ = 'agung.santoso.pranoto (Agung Santoso Pranoto)'

import getopt
import mimetypes
import os.path
import sys

import gdata.sample_util
import gdata.sites.client
import gdata.sites.data

SOURCE_APP_NAME = 'googleInc-GoogleSitesAPIPythonLibSample-v1.1'

TIPITAKA_MULA = ['Tipitaka',
				'Tipitaka (Mula)',
				'Vinayapitaka',
				'Parajikapali',
				'Pacittiyapali',
				'Mahavaggapali',
				'Culavaggapali',
				'Parivarapali',
				'Suttapitaka',
				'Dighanikaya',
				'Majjhimanikaya',
				'Samyuttanikaya',
				'Anguttaranikaya',
				'Khuddakanikaya',
				'Abhidhammapitaka',
				'Dhammasanganipali',
				'Vibhangapali',
				'Dhatukathapali',
				'Punggalapannattipali',
				'Kathavatthupali',
				'Yamakapali-1',
				'Yamakapali-2',
				'Yamakapali-3',
				'Patthanapali-1',
				'Patthanapali-2',
				'Patthanapali-3',
				'Patthanapali-4',
				'Patthanapali-5']

VINAYA_PITAKA = ['Veranjakandam',
				'1. Parajikakandam',
				'2. Sanghadisesakandam',
				'3. Aniyatakandam',
				'4. Nissaggiyakandam',
				'5. Pacittiyakandam',
				'6. Patidesaniyakandam',
				'7. Sekhiyakandam',
				'8. Adhikaranasamatha',
				'1. Parajikakandam (bhikkhunivibhango)',
				'2. Sanghadisesakandam (bhikkhunivibhango)',
				'3. Nissaggiyakandam (bhikkhunivibhango)',
				'4. Pacittiyakandam (bhikkhunivibhango)',
				'5. Patidesaniyakandam (bhikkhunivibhango)',
				'6. Sekhiyakandam (bhikkhunivibhango)',
				'7. Adhikaranasamatha (bhikkhunivibhango)',
				'1. Mahakhandhako',
				'2. Uposathakkhandhako',
				'3. Vassupanayikakkhandhako',
				'4. Pavaranakkhandhako',
				'5. Cammakkhandhako',
				'6. Bhesajjakkhandhako',
				'7. Kathinakkhandhako',
				'8. Civarakkhandhako',
				'9. Campeyyakkhandhako',
				'10. Kosambakakkhandhako',
				'1. Kammakkhandhakam',
				'2. Parivasikakkhandhakam',
				'3. Samuccayakkhandhakam',
				'4. Samathakkhandhakam',
				'5. Khuddakavatthukkhandhakkam',
				'6. Senasanakkhandhakam',
				'7. Sanghabhedakakkhandhakam',
				'8. Vattakkhandhakam',
				'9. Patimokkhatthapanakkhandhakam',
				'10. Bhikkhunikkhandhakam',
				'11. Pancasatikakkhandhakam',
				'12. Sattasatikakkhandhakam',
				'Solasamahavaro',
				'Sammutthanasisasankhepo',
				'Antarapeyyalam',
				'Khandhakapucchavaro',
				'Ekuttarikanayo',
				'Uposathadipucchavissajjana',
				'Gathasanganikam',
				'Adhikaranabhedo',
				'Aparagathasanganikam',
				'Codanakandam',
				'Culasangamo',
				'Mahasangamo',
				'Kathinabhedo',
				'Upalipancakam',
				'Atthapattisamutthanam',
				'Dutiyagathasanganikam',
				'Sedamocanagatha',
				'Pancavaggo']

class SitesStructureCreator(object):
	"""Class untuk membuat struktur tipitaka"""

	def __init__(self, site_name=None, site_domain=None, debug=False):

	    mimetypes.init()

	    self.client = gdata.sites.client.SitesClient(
	        source=SOURCE_APP_NAME, site=site_name, domain=site_domain)
	    self.client.http_client.debug = debug

	    try:
	      gdata.sample_util.authorize_client(
	          self.client, auth_type=1, service=self.client.auth_service, source=SOURCE_APP_NAME,
	          scopes=['http://sites.google.com/feeds/',
	                  'https://sites.google.com/feeds/'])
	    except gdata.client.BadAuthentication:
	      exit('Invalid user credentials given.')
	    except gdata.client.Error:
	      exit('Login Error')

	def Run(self):

		print "\nFetching content feed of '%s'...\n" % self.client.site

		feed = self.client.GetContentFeed()

		pages = VINAYA_PITAKA

		for page_title in pages:

			parent = None

			new_entry = self.client.CreatePage('webpage', page_title, '<b>Your html content</b>',parent=parent)

			print '%s %s' % (page_title, 'created!')



def main():
  """Untuk memulai proses pembuatan struktur tipitaka"""

  structureCreator = SitesStructureCreator('tipitakabahasaindonesia', 'site', False)
  structureCreator.Run()


if __name__ == '__main__':
  main()